<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="所属站点">
        <el-radio-group v-model="form.site_id" @change="search">
          <el-radio-button :label="0">全部</el-radio-button>
          <el-radio-button
            v-for="item in cityList"
            :key="item.site_id"
            :label="item.site_id"
            :value="item.site_id"
          >
            {{ item.region_name }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>

      <br />
      <el-form-item label="所属公司">
        <el-radio-group v-model="form.tenant_id" @change="search">
          <el-radio-button :label="0" :value="0"> 全部 </el-radio-button>
          <el-radio-button
            v-for="item in tenantList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button :label="99">全部</el-radio-button>
          <el-radio-button :label="0">
            财务审核
            <span
              v-if="props.watingData.watingJudge > 0"
              class="radio-group-tips"
            >
              {{ props.watingData.watingJudge }}
            </span>
          </el-radio-button>
          <el-radio-button :label="11">
            财务主管审核
            <span
              v-if="props.watingData.watingDoubleJudge > 0"
              class="radio-group-tips"
            >
              {{ props.watingData.watingDoubleJudge }}
            </span>
          </el-radio-button>
          <el-radio-button :label="1">
            经理审核
            <span
              v-if="props.watingData.watingReJudge > 0"
              class="radio-group-tips"
            >
              {{ props.watingData.watingReJudge }}
            </span>
          </el-radio-button>
          <el-radio-button :label="2">
            待打款
            <span
              v-if="props.watingData.watingPay > 0"
              class="radio-group-tips"
            >
              {{ props.watingData.watingPay }}
            </span>
          </el-radio-button>
          <el-radio-button :label="8">已完成</el-radio-button>
          <el-radio-button :label="9">未通过</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="所属项目">
        <el-select
          v-model="form.project_id"
          placeholder=""
          style="width: 200px"
          @change="search"
        >
          <el-option label="全部项目" :value="0">全部项目</el-option>
          <el-option
            v-for="item in projectList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="报销分类">
        <el-select v-model="form.cate_id" style="width: 200px" @change="search">
          <el-option label="全部分类" :value="0">全部分类</el-option>
          <el-option
            v-for="item in cateList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <br />
      <el-form-item label="申请时间">
        <el-date-picker
          v-model="form.startDate"
          class="filter-item"
          type="date"
          placeholder="开始"
          value-format="YYYY-MM-DD"
          style="width: 150px"
        />
        <el-date-picker
          v-model="form.endDate"
          class="filter-item"
          type="date"
          placeholder="结束"
          value-format="YYYY-MM-DD"
          style="width: 150px; margin-left: 8px"
        />
      </el-form-item>

      <br />

      <el-form-item label="申请人">
        <el-input clearable v-model.trim="form.create_user" />
      </el-form-item>
      <el-form-item label="审核人">
        <el-input clearable v-model.trim="form.judge_user" />
      </el-form-item>
      <el-form-item label="打款人">
        <el-input clearable v-model.trim="form.pay_user" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { EleMessage } from 'ele-admin-plus/es';
  import { getCityList } from '@/api/system/region';
  import { getTenantList } from '@/api/tenant';

  import { pageOaProject, pageOaCate } from '@/api/oa';
  import { useFormData } from '@/utils/use-form-data';
  import { ref } from 'vue';
  const emit = defineEmits(['search']);

  const props = defineProps({
    watingData: Object,
    where: Object
  });

  /** 项目列表 */
  const projectList = ref([]);
  const cateList = ref([]);

  /** 表单数据 */
  const [form] = useFormData({
    cate_id: 0,
    project_id: 0,
    site_id: 0,
    startDate: '',
    endDate: '',
    status: 0,
    create_user: '',
    judge_user: '',
    pay_user: '',
    tenant_id: 0
  });
  if (props.where) {
    form.startDate = props.where.startDate ?? '';
    form.endDate = props.where.endDate ?? '';
    form.status = props.where.status ?? 0;
  }
  /** 站点数据 */
  const cityList = ref([]);

  /** 获取站点数据 */
  getCityList({})
    .then((res) => {
      cityList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });
  /** 租户数据 */
  const tenantList = ref([]);

  /** 获取租户数据 */
  getTenantList({})
    .then((res) => {
      tenantList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 项目列表 */
  pageOaProject({})
    .then((res) => {
      projectList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 分了以列表 */
  pageOaCate({})
    .then((res) => {
      cateList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
